<?php

require_once '../db/connect.php';

function getAllUsers($con) {
    if (!$con) {
        $con = getNewDatabaseConnection();
    }
    
    // execute query
    $sql = "SELECT * FROM foggy.users";
    $result = pg_query($con, $sql);
    if (!$result) {
        die("Error in SQL query: " . pg_last_error());
    }

    // iterate over result set
    // print each row
    echo "<br />";
    while ($row = pg_fetch_array($result)) {
        echo "id: " . $row['id'] . "<br />";
        echo "First Name: " . $row['first_name'] . "<br />";
        echo "Last Name: " . $row['last_name'] . "<br />";
        echo "email: " . $row['email'] . "<br />";
    }

    endQuery($con, $result);
}

getAllUsers(getNewDatabaseConnection());

class User {

    // property declaration
    public $id;
    public $email;
    public $first_name;
    public $last_name;
    public $location;
    public $facebook_user_id;

    // toString overridden
    public function __toString() {
        return $this->email;
    }

}

?>